<template>
<view class="uni-common-pb">
    <view class="fixbk">
        <view class="act-image">
            <image :src="actData.img?actData.img:dimg" mode="widthFix"></image>
        </view>
        <view class="act-info">  
            <view class="tit">{{actData.name}}</view>          
            <view class="info">
                {{actData.info}}
            </view>
            
            <view class="item-list">
                <view class="list">
                    <text class="zkicon">&#xe723;</text>{{reTime}}
                </view>
                <view class="list" @click="showMap">
                    <text class="zkicon">&#xe657;</text>西区小榄公<text class="zkicon fr">&#xe7f9;</text>
                </view>
            </view>

        </view>

        <view class="act-signInList">
            <view class="title">签到列表</view>
            <view class="uni-list">
                <view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(value,key) in sign_lists" :key="key">
                    <view class="uni-media-list">
                        <view class="uni-media-list-logo">
                            <image :src="value.avatarUrl"></image>
                        </view>
                        <view class="uni-media-list-body">
                            <view class="uni-media-list-text-top">{{value.nickName}}</view>
                            <view class="uni-media-list-text-bottom uni-ellipsis">{{value.time}}</view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>

    <view class="bottom-btn-box">
        <view class="fl"><button type="default" @click="goHome" class="custom-btn"><text class="zkicon">&#xe607;</text></button></view>    
        <view class="fr2"><button type="default" open-type="share" class="custom-btn"><text class="zkicon">&#xe608;</text></button></view>
        <view class="fr"><button type="primary" @click="getSignUp" class="custom-btn btn-blue"><text class="zkicon">&#xe639;</text>签到</button></view>
        <view class="fc"><button type="primary" @click="goBless(aid)" class="custom-btn btn-org"><text class="zkicon">&#xe6cd;</text>发送祝福</button></view>
    </view>
</view>
</template>
<script>
import {formatDate,formatObjDate,formatOneDate,get,post} from '@/utils/index';
import {getActDetails,getSignList,signUp} from '@/utils/api';
export default {
    data () {
        return {
            aid:0,
            actData:{},
            test:'actData.name',
            dimg:'../../../static/nopic.png',
            sign_lists: [
                {
                "uid":1,
                "nickName":"路人甲",
                "age":"24"
                },
                {
                "uid":2,
                "nickName":"程小姐",
                "age":"21"
                }
            ],
            title: 'media-list',
            showImg: false,
            list: [{
                    title: "幸福",
                    content: "能和心爱的人一起睡觉，是件幸福的事情；可是，打呼噜怎么办？",
                    img: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/shuijiao.jpg?imageView2/3/w/200/h/100/q/90"
                },
                {
                    title: "木屋",
                    content: "想要这样一间小木屋，夏天挫冰吃瓜，冬天围炉取暖。",
                    img: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/muwu.jpg?imageView2/3/w/200/h/100/q/90"
                }
            ],
            userInfo : uni.getStorageSync('userInfo')
        }
    },
    onShareAppMessage(res) {
        // if (res.from === 'button') {// 来自页面内转发按钮
        //     console.log(res.target)
        // }
        return {
            title: '分享活动',
            path: '/pages/tabBar/act/act'
        }
    },
    onLoad:function(option){
        this.aid =option.id;
        uni.connectSocket({
            url: 'wss://wx.igiky.cn/wss'
        });
        uni.onSocketMessage(function (res) {
            console.log('收到服务器内容：' , res);
            let obj = JSON.parse(res.data)
            // that.barrageList.push(obj)
        });
    },
    onShow:function(){
        
    },
    onUnload:function(){
        console.log('已关闭！');
        

        uni.onSocketClose(function (res) {
        console.log('WebSocket 已关闭！');
        });
    },
    computed:{
        reTime(){
            return formatDate(this.actData.atime)
        }
    },
    mounted(){
        // console.log(formatTime(1546064719))
        this.init();
    },
    methods:{
        init(){
            this.getAct()
            let user  = uni.getStorageSync('userInfo')
            
        },
        openLocation: function (e) {
            console.log(e)
            var value = e.target.value
            uni.openLocation({
                longitude: Number(value.longitude),
                latitude: Number(value.latitude),
                name: value.name,
                address: value.address
            })
        },
        showMap() {
            this.openLocation({
				target:{
					value:{
						longitude: 113.359955,
						latitude: 22.538668,
						name: '小榄公',
						address: '嘉华互联网中心隔壁'
					}
				}
			})
        },
        getMap(){
            uni.navigateTo({
                url: '/pages/open-location/open-location'
            });
        },
        goHome(){
            uni.switchTab({
                url: '/pages/tabBar/home/home'
            });
        },
        goBless(id){
            uni.navigateTo({
                url: '/pages/bless/bless?id='+id
            });
        },
        getAct(){
            var that = this;
            uni.showNavigationBarLoading();
            this.more  = true;
            get(getActDetails,{
                aid: that.aid
            }, true)
            .then((res)=>{
                console.log(8,res)
                this.actData = res.data.act
                formatObjDate(res.data.signList).then((data)=>{
                    this.sign_lists = data
                })
                // this.sign_lists = res.data.signList
                uni.hideNavigationBarLoading();
            })
        },
        getSignUp(){
            post(signUp,{
                openid:this.userInfo.openid,
                actId:this.aid
            }, true)
            .then((res)=>{
                console.log(11,res)
                if(res.code==0){
                    formatOneDate(res.data).then((data)=>{
                        // this.sign_lists = data
                        console.log(123,data)
                        this.sign_lists.unshift(data)
                    })
                    
                }                
                uni.showModal({
                    title: '提示',
                    content: res.msg,
                    showCancel:false,
                    success: function (res) {
                        if (res.confirm) {
                            console.log('用户点击确定');
                        } else if (res.cancel) {
                            console.log('用户点击取消');
                        }
                    }
                });
            })
        }
    },
    filters: {
      
    }

}
</script>

<style scoped>
.fixbk{
    margin:20upx 0 100upx 0;
}
</style>
